﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Chinook.Core;
using Chinook.Data;
using Base.Data;
using Chinook.Core.DaoInterface;
using Chinook.Core.DomainModel;
using NHibernate;
using NHibernate.Criterion;
using NHibernate.Criterion.Lambda;
using Base.Common;

namespace Chinook.Data
{
    public class EmployeeDao : AbstractNHibernateDao<Employee, long>, IEmployeeDao
    {

        #region IEmployeeDao Members

        public PagedList<Employee> GetEmployeeByName(string employeeName, int pageIndex, int pageSize)
        {
           
            return NHibernateSession.QueryOver<Employee>()                
                .Where(Restrictions.On<Employee>(m => m.FirstName).IsLike("%" + employeeName + "%") ||
                            Restrictions.On<Employee>(m => m.LastName).IsLike("%" + employeeName + "%"))                      
                .OrderBy(m => m.FirstName).Asc
                .ToPagedList(pageIndex, pageSize);
                //.List();
        }

        #endregion
    }
}
